param(
    [string]$Input = "..\examples\compute.ll",
    [string]$Arch = "x86-64",
    [string]$OutputDir = "..\build"
)

if (-not (Test-Path $OutputDir)) {
    New-Item -ItemType Directory -Path $OutputDir | Out-Null
}

$bcPath = Join-Path $OutputDir "compute.bc"
$asmPath = Join-Path $OutputDir "compute.s"
$objPath = Join-Path $OutputDir "compute.obj"
$exePath = Join-Path $OutputDir "compute.exe"

Write-Host ">> llvm-as $Input -o $bcPath"
llvm-as $Input -o $bcPath

Write-Host ">> llc -march=$Arch $bcPath -filetype=asm -o $asmPath"
llc -march=$Arch $bcPath -filetype=asm -o $asmPath

Write-Host ">> llc -march=$Arch $bcPath -filetype=obj -o $objPath"
llc -march=$Arch $bcPath -filetype=obj -o $objPath

Write-Host ">> clang $objPath -o $exePath"
clang $objPath -o $exePath

Write-Host "完成，输出位于 $OutputDir"
